//
//  LGSportOrderTableViewCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/11/6.
//

#import "LGSportOrderTableViewCell.h"

@interface LGSportOrderTableViewCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIView *lineView;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *timeIcon;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**   */
@property (nonatomic , strong)UILabel *hospitalLabel;
/**   */
@property (nonatomic , strong)UILabel *priceLabel;

@end

@implementation LGSportOrderTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setAppointDic:(NSDictionary *)appointDic{
    _appointDic = appointDic;
    self.titleLabel.text = LGNSString(appointDic[@"type_name"]);
    self.statusLabel.text = LGNSString(appointDic[@"state_name"]);
    //10：待支付 20：已取消 30：待接诊 31：咨询中   40 已完成  41：已爽约  42 ：未接通  50：已退款
    NSString *state = LGNSString(appointDic[@"state"]);
    NSDictionary *statusDic = @{@"10":@"#3291FF",@"20":@"#999999",@"30":@"#3291FF",@"31":@"#3291FF",@"40":@"#999999",@"41":@"#999999",@"42":@"#DD3030",@"50":@"#999999"};
    self.statusLabel.textColor = [UIColor colorWithString:statusDic[state]];
    NSDictionary *patientDic = appointDic[@"patient"];
    UIImage *placeHolder = [LGNSString(patientDic[@"gender"]) isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:patientDic[@"avatar_url"]] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(patientDic[@"realname"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",patientDic[@"gender"],patientDic[@"age"]];
    self.timeLabel.text = [NSString stringWithFormat:@"%@ %@ %@号",appointDic[@"visit_date"],appointDic[@"visit_start_time"],appointDic[@"appointment_no"]];
    
    self.hospitalLabel.text = LGNSString(appointDic[@"visit_address_short"]);
    NSString *colorName = [LGNSString(appointDic[@"visit_address_short"]) isEqualToString:@"温江院区"]?@"#DD3030":@"#666666";
    self.hospitalLabel.textColor = [UIColor colorWithString:colorName];
    self.priceLabel.text = @"";
}

-(void)setOrderDic:(NSDictionary *)orderDic{
    _orderDic = orderDic;
    self.titleLabel.text = LGNSString(orderDic[@"goods_name"]);
    self.statusLabel.text = LGNSString(orderDic[@"state_name"]);
    //10：待支付 20：已取消 30：待接诊 31：咨询中   40 已完成  41：已爽约  42 ：未接通  50：已退款
//    NSString *state = LGNSString(orderDic[@"state"]);
//    NSDictionary *statusDic = @{@"10":@"#3291FF",@"20":@"#999999",@"30":@"#3291FF",@"31":@"#3291FF",@"40":@"#999999",@"41":@"#999999",@"42":@"#DD3030",@"50":@"#999999"};
    self.statusLabel.textColor = [UIColor colorWithString:@"#999999"];
    UIImage *placeHolder = [LGNSString(orderDic[@"gender"]) isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:orderDic[@"avatar_url"]] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(orderDic[@"patient_name"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",orderDic[@"gender"],orderDic[@"age"]];
    self.timeLabel.text = LGNSString(orderDic[@"pay_time"]);
    self.hospitalLabel.text = @"";
    self.priceLabel.text = [NSString stringWithFormat:@"¥ %@",orderDic[@"goods_total"]];
}

-(void)createSubView{
    self.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.titleLabel];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.lineView];
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.timeIcon];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.hospitalLabel];
    [self.baseView addSubview:self.priceLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(6));
        make.centerY.equalTo(self.iconView);
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.iconView);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.headPic);
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(5));
        make.centerY.equalTo(self.headPic);
    }];
    
    [self.timeIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headPic.mas_bottom).offset(viewPix(12));
        make.left.equalTo(self.headPic);
        make.width.height.equalTo(@(viewPix(16)));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeIcon.mas_right).offset(viewPix(3));
        make.centerY.equalTo(self.timeIcon);
    }];
    [self.hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.mas_right).offset(viewPix(4));
        make.centerY.equalTo(self.timeIcon);
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.timeIcon);
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.frame = CGRectMake(viewPix(16), viewPix(6), Screen_W-viewPix(32), viewPix(132));
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(12), viewPix(20), viewPix(20))];
        _iconView.image = [UIImage imageNamed:@"我的订单-运动评估"];
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"专家咨询" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"已完成" colorString:@"#999999" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _statusLabel;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(44), Screen_W-viewPix(32)-viewPix(24), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), kMaxY(self.lineView.frame)+viewPix(12), viewPix(32), viewPix(32))];
        _headPic.cornerRidus = 5;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)timeIcon{
    if(!_timeIcon){
        _timeIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的订单-订单时间"]];
    }
    return _timeIcon;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UILabel *)hospitalLabel{
    if(!_hospitalLabel){
        _hospitalLabel = [UILabel lableWithText:@"" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _hospitalLabel;
}

-(UILabel *)priceLabel{
    if(!_priceLabel){
        _priceLabel = [UILabel lableWithText:@"" colorString:@"#3291FF" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _priceLabel;
}

@end
